package lu.med.praxiswahl.wahlumed.client.oprechnungen;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import lu.med.praxiswahl.wahlumed.client.tarif.TarifTableModel;
import lu.med.praxiswahl.wahlumed.client.utilities.UniCode;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;


/**
 * 
 * @author Lars Holger Roth
 */
public class OPRechnungenTarifauswahlKlasseZwei extends JDialog implements
	ActionListener
{
    private TarifTableModel model;
    private OPRechnungenUnterPanelKlasseZwei owner;
    private JCheckBox[] check;
    private String[] key;

    public OPRechnungenTarifauswahlKlasseZwei(
	    OPRechnungenUnterPanelKlasseZwei owner, Main dataManager,
	    TarifTableModel model)
    {
	super(dataManager, "Code Tarif", true);
	this.setLayout(new BorderLayout());
	this.model = model;
	this.owner = owner;

	JPanel optionspanel = new JPanel(new GridLayout(0, 2));

	check = new JCheckBox[model.getSize()];
	key = new String[model.getSize()];

	for (int i = 0; i < model.getSize(); i++)
	{
	    key[i] = model.getKeywordAt(i);
	    optionspanel.add(new JLabel(key[i]));
	    check[i] = new JCheckBox(model.getDescriptionAt(i));
	    optionspanel.add(check[i]);
	}

	JPanel buttonPanel = new JPanel();
	JButton ok = new JButton("" + UniCode.getUE() + "bernehmen");
	ok.addActionListener(this);
	JButton cancel = new JButton("Abbrechen");
	cancel.addActionListener(this);
	buttonPanel.add(ok);
	buttonPanel.add(cancel);

	JScrollPane optionspanelPane = new JScrollPane(optionspanel);

	this.add(optionspanelPane, BorderLayout.CENTER);
	this.add(buttonPanel, BorderLayout.SOUTH);

	this.pack();
	this.setLocation(100, 20);
	this.setVisible(true);
    }

    public void actionPerformed(ActionEvent e)
    {
	if (e.getActionCommand().equals("" + UniCode.getUE() + "bernehmen"))
	{
	    // Tr�gt die ausgew�hlten Optionen in die Rechnung ein
	    for (int i = 0; i < check.length; i++)
	    {
		if (check[i].isSelected())
		    owner.addCode(key[i]);
	    }
	    this.setVisible(false);
	}
	else
	{
	    this.setVisible(false);
	}
    }

}
